package com.wyix.service;

import java.util.concurrent.Callable;

/**
 * @author wangdx
 * @since 2025/8/1
 */
public class PaymentTask implements Callable<Boolean> {
    private String orderId;
    private double amount;

    public PaymentTask(String orderId, double amount) {
        this.orderId = orderId;
        this.amount = amount;
    }

    @Override
    public Boolean call() throws Exception {
        System.out.println("线程[" + Thread.currentThread().getName() + "]处理支付：" + orderId);
        Thread.sleep(1500); // 模拟第三方支付接口耗时1.5秒
        return callPaymentAPI(orderId, amount); // 返回支付结果
    }

    private Boolean callPaymentAPI(String orderId, double amount) {
        // 模拟调用第三方支付接口
        System.out.println("调用第三方支付接口，订单ID：" + orderId + "，金额：" + amount);
        return true; // 假设支付成功
    }
}